package com.chat.transmission.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wei kunJie
 * @date 2024/3/23 16:42:18
 */
@Configuration
@EnableAsync//起用异步支持
public class ThreadTaskConfig {
    @Bean
    public ConcurrentHashMap<String,Object> getMsgEventSourceMap(){
        return new ConcurrentHashMap<>();
    }

    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10); // 核心线程数
        executor.setMaxPoolSize(100); // 最大线程数
        executor.setThreadNamePrefix("custom-thread-"); // 线程名称前缀
        executor.initialize();
        return executor;
    }

//    @Bean
//    public EventLoopGroup eventLoopGroup(){
//        return new NioEventLoopGroup();
//    }
//
//    @Bean
//    public Bootstrap bootstrap(EventLoopGroup eventLoopGroup){
//        Bootstrap bootstrap = new Bootstrap();
//        bootstrap.group(eventLoopGroup)
//                .channel(NioDatagramChannel.class)
//
//    }
}
